﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;

namespace NetCore.Filters
{
    /// <summary>
    /// 放在全局
    /// </summary>
    public class CustomGlobalActionFilterAttribute : Attribute, IActionFilter
    {
        private ILogger<CustomGlobalActionFilterAttribute> _logger = null;
        public CustomGlobalActionFilterAttribute(ILogger<CustomGlobalActionFilterAttribute> logger)
        {
            this._logger = logger;
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine("CustomGlobalActionFilterAttribute Executed!");
            this._logger.LogDebug("CustomGlobalActionFilterAttribute Executed!");
            //context.HttpContext.Response.WriteAsync("CustomGlobalActionFilterAttribute Executed!");
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine("CustomGlobalActionFilterAttribute Executing!");
            this._logger.LogDebug("CustomGlobalActionFilterAttribute Executing!");
            //context.HttpContext.Response.WriteAsync("CustomGlobalActionFilterAttribute Executing!");
        }
    }
}
